package com.doupi.partner.dal;

import com.doupi.partner.model.PartnerRelation;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

public interface PartnerRelationMapper {
	int deleteByPrimaryKey(Long id);

	int insert(PartnerRelation record);

	PartnerRelation selectByPrimaryKey(Long id);

	int updateByPrimaryKeySelective(PartnerRelation record);

	int countPartnerRelation(PartnerRelation partnerRelation);

	List<PartnerRelation> queryPartnerRelations(PartnerRelation partnerRelation, RowBounds rowBounds);

	List<PartnerRelation> selectPartnerRelationForUpdate(PartnerRelation partnerRelation);

	PartnerRelation selectPartnerRelationForUpdateByPrimaryKey(Long id);

	@Select("<script>select count(1) from t_partner_relation  <where> " + "<trim prefix=\"(\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"superiorAdministratorId != null\">or superior_administrator_id = #{superiorAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim> and `type` = #{type,jdbcType=TINYINT}"
			+ " </where></script>")
	int countPartnerRelationWithAnnotation(PartnerRelation partnerRelation);

	@Select("<script>select * from t_partner_relation  <where> " + "<trim prefix=\"(\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"superiorAdministratorId != null\">or superior_administrator_id = #{superiorAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim> and `type` = #{type,jdbcType=TINYINT}"
			+ "</where></script>")
	@ResultMap("com.doupi.partner.dal.PartnerRelationMapper.BaseResultMap")
	List<PartnerRelation> queryPartnerRelationsWithAnnotation(PartnerRelation partnerRelation, RowBounds rowBounds);
}
